#include "stdafx.h"
#include "proxy.h"
#include "httpconnection.h"


Proxy::Proxy(void):listenServer(*(new QTcpServer))
{
	connect(&listenServer, SIGNAL(newConnection()),
					this,  SLOT(AcceptConnection())); 

	listenServer.listen(QHostAddress::LocalHost, 3128);
}

Proxy::~Proxy(void)
{
	listenServer.close();
}

void Proxy::AcceptConnection()
{
//	QApplication::beep ()   ;
	QTcpSocket* sock=listenServer.nextPendingConnection();
	new HttpConnection(sock);
	//connect(sock, SIGNAL(readyRead()),
 //                 this,  SLOT(DataRecieved())); 
}

void Proxy::DataRecieved()
{
	ui->Request->setPlainText(ui->Request->toPlainText()+
		QString(static_cast<QTcpSocket*>(QObject::sender())->readAll()));
}